package finance

import org.apache.commons.math.distribution.NormalDistributionImpl

class TheoDistService {
    
    static transactional = true
    
    def normalPDF(mean, stddev, x) {
        return new NormalDistributionImpl(mean, stddev).density(x)
    }
    
    def gaussExpected(mean, stddev, xpoints) {
        def expected = []
        def sortedPoints = xpoints.sort()
        
        sortedPoints.each {
            expected << normalPDF(mean, stddev, it)
        }
        
        return expected
    }
    
    def levyExpected( c, xpoints , mu) {
        def expected = []
        def sortedPoints = xpoints.sort()
        
        sortedPoints.each {
            expected << levyPDF( c, it, mu )
        }
        
        return expected
    } 
    
    def levyPDF( c, x, mu ) {
        def constant = c / (2 * Math.PI)
        def exponent = Math.exp(-1 * c / (2 * (x - mu) ))
        def pow32 = Math.pow(x - mu, 3/2)
        return Math.sqrt( constant )  * exponent / pow32
    }
}
